<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div class="box">
        <span>11</span>
        <p>11</p>
        <H1>22</H1>
    </div>

    <div class="a">
        <span>22</span>
        <strong>222</strong>
        <p>22</p>
        <h2>33</h2>
        <div>44</div>
    </div>

    <script>

        function Get(el) {
            this.el = document.querySelectorAll(el);

            // prevAll

            this.siblings = function () {
                const arr = [];   // 搞新的数组
                // 找所有的兄弟   --- 找到父元素的孩子，排除了自己
                for (let i = 0; i < this.el.length; i++) {
                    // 转真数组
                    const child = [...this.el[i].parentElement.children];
                    // console.log(child);
                    // 排除p  
                    //    思路1   搞新的数组
                    // 遍历child   把不是p的都push进去
                    // for (let j = 0; j < child.length; j++) {
                    //     if (child[j] !== this.el[i])
                    //         arr.push(child[j])
                    // }

                    //    思路2   把p删除
                    //       pop()尾部删除  shift()头部删除   splice()利用下标
                    const x = child.indexOf(this.el[i]);   // 找下标
                    console.log(x);
                    child.splice(x, 1);    // 根据下标删除数组中的p
                    console.log(child);

                    arr.push(...child);
                }

                console.log(arr);

            }
        }


        new Get('span').siblings()

    </script>

</body>

</html>